package com.xiedafeng.www.view;

import com.xiedafeng.www.controller.InformationController;
import com.xiedafeng.www.po.User;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class UpdateInformationView {
    TextField nameField =new TextField();
    TextField sexField =new TextField();
    TextField birthdayField =new TextField();
    TextField introduceField =new TextField();
    Stage stage=new Stage();
    public void show(User user) {
        GridPane gridPane=new GridPane();
        Text name=new Text();
        name.setText("姓名");
        gridPane.add(name,0,0);
        Text sex=new Text();
        sex.setText("性别");
        gridPane.add(sex,0,1);
        Text birthday=new Text();
        birthday.setText("生日(xx年xx月xx日)");
        gridPane.add(birthday,0,2);
        Text introduce=new Text();
        introduce.setText("个人说明");
        gridPane.add(introduce,0,3);
        gridPane.add(nameField,1,0);
        gridPane.add(sexField,1,1);
        gridPane.add(birthdayField,1,2);
        gridPane.add(introduceField,1,3);
        Button update=new Button("修改");
        gridPane.add(update,1,4);
        gridPane.setAlignment(Pos.CENTER);
        update.setOnMouseClicked(event -> {
            try {
                update(user);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        Scene scene=new Scene(gridPane);
        stage.setScene(scene);
        stage.showAndWait();
    }
    private void update(User user) throws Exception {
        user.setName(nameField.getText());
        user.setSex(sexField.getText());
        user.setBirthday(birthdayField.getText());
        user.setSelfIntroduce(introduceField.getText());
        InformationController informationController =new InformationController();
        informationController.update(user);
    }
    public void close(){
        stage.close();
    }
}
